/**
 * 管理初始化
 */
var Record = {
    id: "RecordTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Record.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '卡号', field: 'cardno', visible: true, align: 'center', valign: 'middle'},
            {title: '生成时间', field: 'time', visible: true, align: 'center', valign: 'middle'},
            {title: '开门状态', field: 'note1', visible: true, align: 'center', valign: 'middle'},
            {title: '门号', field: 'note2', visible: true, align: 'center', valign: 'middle'},
            {title: '进出', field: 'note3', visible: true, align: 'center', valign: 'middle'},
    ];
};

/**
 * 检查是否选中
 */
Record.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Record.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
Record.protection = function () {
    $.ajax({
        url: "http://localhost:8082/park/interface/111",//获取数据的URL
        type: "Get",//HTTP请求方法
        async: false,
        success: function (data) {

        }
    });
};

/**
 * 清空
 */
Record.deleteAll = function () {
    $.ajax({
        url: Feng.ctxPath +"/record/deleteAll",//获取数据的URL
        type: "Post",//HTTP请求方法
        async: false,
        success: function (data) {
            Feng.success("删除成功!");
            Record.table.refresh();
        },
        error:function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        }
    });
};

/**
 * 删除
 */
Record.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/record/delete", function (data) {
            Feng.success("删除成功!");
            Record.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("recordId",this.seItem.id);
        ajax.start();
    }
};
Record.download=function(){
    window.location.href="/record/download";
   /* $.ajax({
        url: Feng.ctxPath +"/record/download",//获取数据的URL
        type: "Post",//HTTP请求方法
        async: false,
        success: function (data) {
            Feng.success("下载成功!");
            Record.table.refresh();
        },
        error:function (data) {
            Feng.error("下载失败!" + data.responseJSON.message + "!");
        }
    });*/
}
/**
 * 查询列表
 */
Record.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['cardNo'] = $("#cardNo").val();
    queryData['status'] = $("#status").val();
    queryData['doorNumber'] = $("#doorNumber").val();
    queryData['inOrGo'] = $("#inOrGo").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();

    Record.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Record.initColumn();
    var table = new BSTable(Record.id, "/record/list", defaultColunms);
    table.setPaginationType("client");
    Record.table = table.init();
});
